package com.zl.controller;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import com.select.pojo.Courses;
import com.select.utils.CommonResult;
import com.zl.feign.TeaFeign;
import com.zl.pojo.vo.AchievementVo;
import com.zl.pojo.vo.ElectiveVo;
import com.zl.pojo.vo.SelVo;
import com.zl.service.SelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author ：ZhangLei
 * @Data ：2021/5/21 11:31
 * @Description ：
 */
@RestController
@RequestMapping("/student")
public class SelController {

    @Autowired
    private SelService selService;
    @Autowired
    private TeaFeign teaFeign;

    @Autowired
    private LoginController loginController;

    @GetMapping("/getCourse")
    public CommonResult getCourse (String couGrade, String couDepartment,
                                   String couDepartment2, String couWeek,
                                   String couTime,String toke,String stuAccount){
        List<SelVo> list = selService.getCourse(couGrade,couDepartment,couDepartment2,
                                                  couWeek,couTime,stuAccount);
        return CommonResult.ok("成功",list);
    }


    /**
     * 插入学生选课
     *
     * @param stuAccount
     * @param couId
     * @param stuName
     * @return
     */
    @PostMapping("/insertCouser")
    public CommonResult insertCouser(String stuAccount, String couId, String stuName, Integer couStuNum) {
        System.out.println(stuAccount);
        System.out.println(couId);
        System.out.println(stuName);
        System.out.println(couStuNum);
        Integer i = selService.insertcouser(stuAccount, couId, stuName, couStuNum);
        return CommonResult.ok(200,i,"成功");
    }

    /**
     * 查看学生已选课程
     *
     * @param stuAccount
     * @param courseFlag
     * @return
     */
    @GetMapping("/selectele")
    public CommonResult selectele(String stuAccount, String courseFlag) {
        ElectiveVo selectele = selService.selectele(stuAccount, courseFlag);
        List list = new ArrayList();
        list.add(selectele);
        return CommonResult.ok(200, list, "查看学生已选选课");
    }

    /**
     * 查询成绩
     *
     * @param stuAccount
     * @param semester
     * @return
     */
    @GetMapping("/selectach")
    public CommonResult selectach(String stuAccount, String semester) {
        List<AchievementVo> list = selService.selectach(stuAccount, semester);
        return CommonResult.ok(200, list, "查看成绩成功");
    }

    @GetMapping("/selectSem")
    public CommonResult selectSem(){
        List<String> semesters = selService.selectSem();
        return CommonResult.ok(200,semesters,"查看学期成功");
    }

    @GetMapping("/teacher/findAll")
    public CommonResult findOne(String teaAccount){
        List<Courses> list = teaFeign.findOne(teaAccount);
        if (list == null){
            return CommonResult.ok(565,null,"请稍候重试");
        }
        return CommonResult.ok(200,list,"查看学期成功");
    }



}
